home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 020a / bgisnap.zip / BGISNAP.C next >
C/C++ Source or Header  |  1992-01-02  |  4KB  |  85 lines

  1. /**╟─────────────────────────────────────────────────────╢
  2.  **║                                                     ║
  3.  **║      Copyright MCMXCI, Jeffrey Chasen                ║
  4.  **║                                                     ║
  5.  **║                                                                    ║
  6.  **╟─────────────────────────────────────────────────────╢
  7. */
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <fcntl.h>
  12. #include <sys\stat.h>
  13. #include <dos.h>
  14. #include <conio.h>
  15. #include <alloc.h>
  16. #include <graphics.h>
  17.  
  18. /* -------------------------------------------------------------------  */
  19. /* The file created by BGISNap contains a header telling how many image */
  20. /* segments the image was split in to.  Borland BGI has a max size of   */
  21. /* 64K for any given image.                                             */
  22. /*                                                                      */
  23. /* Format of the file created by BGISnap is as follows:                 */
  24. /*     Header  -- (contains 2 bytes which is the number of segments)    */
  25. /*     Byte 1  -- (int) containing the number of image segments         */
  26. /*     Byte 2  -- contained in this file (a segment can be up to 64k)   */
  27. /*                                                                      */
  28. /*     Segment 1 (all byte positions are now relative to this segment)  */
  29. /*     Byte 1 -- (unsigned int) containing the byte size of this segment*/
  30. /*     Byte 2                                                           */
  31. /*                                                                      */
  32. /*     Byte 3 -- (int) containg the X position of the image             */
  33. /*     Byte 4                                                           */
  34. /*                                                                      */
  35. /*     Byte 5 -- (int) containg the Y position of the segment           */
  36. /*     Byte 6                                                           */
  37. /*                                                                      */
  38. /*     Byte 7 -- Beginning of image data (a normal putimage() can be    */
  39. /*               done on his data)                                      */
  40. /*     .............                                                    */
  41. /*     Segment 2 .etc                                                   */
  42. /* -------------------------------------------------------------------  */
  43.  
  44. /* -------------------------------------------------------------------  */
  45. /* This function will display an image snapped by BGISnap into file     */
  46. /* The graphics system must have been previously been initialized       */
  47. /* to the proper mode.                                                  */
  48. /* -------------------------------------------------------------------  */
  49. void displayBGIImage(char *file)
  50. {
  51.     int i, x1, y1, numSegments;
  52.     static char far *buf = NULL;
  53.     unsigned int gSeg, size;    
  54.     FILE *fp;
  55.     
  56.     fp = fopen(file,"rb");
  57.     if (fp == NULL)
  58.         return;
  59.     
  60.     // allocate memory first time from DOS
  61.     // can be changed to allocate each time the function is called
  62.     // or even for each segment
  63.     if (buf == NULL)
  64.     {
  65.         unsigned int size = 64*(1024/16);        // allocate 64K which is
  66.         allocmem(size,&gSeg);                  // the largest a segment can be
  67.         buf = MK_FP(gSeg,0);        
  68.     }
  69.         
  70.     
  71.     fread(&numSegments,1,sizeof(int),fp); // read each segment and
  72.     for (i = 0; i < numSegments; i++)     // display it at the proper position
  73.     {
  74.         fread(&size,1,sizeof(int),fp);        
  75.         fread(&x1,1,sizeof(int),fp);
  76.         fread(&y1,1,sizeof(int),fp);
  77.         fread(buf,1,size,fp);
  78.         putimage(x1,y1,buf,COPY_PUT);
  79.     }
  80.     
  81. /*    freemem(gSeg); can be used to free memory each time if it is needed */
  82.     
  83.     fclose(fp);
  84. }
  85.